//acwing2687    https://www.acwing.com/problem/content/description/2870/

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int months[13] = {
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};

int is_leap(int year)
{
    if (year % 4 == 0 && year % 100 || year % 400 == 0)
        return 1;
    return 0;
}

int get_days(int year, int month)
{
    if (month == 2)
        return months[month] + is_leap(year);
    return months[month];
}

void next_day(int& y, int& m, int& d)
{
    d++;
    if (d > get_days(y, m))
    {
        d = 1;
        m++;
        if (m > 12)
        {
            m = 1;
            y++;
            if (y > 9999) y = 0;
        }
    }
}

bool check1(char str[])
{
    for (int i = 0, j = 7; i <= j; i++, j--)
        if (str[i] != str[j])
            return false;
    return true;
}

bool check2(char str[])
{
    char a = str[0], b = str[1], c = str[2], d = str[3];
    return a != b && a == c && b == d;
}

int main()
{
    int y, m, d;
    scanf("%04d%02d%02d", &y, &m, &d);

    bool found1 = false, found2 = false;
    while (!found1 || !found2)
    {
        next_day(y, m, d);
        char str[10] = { 0 };
        sprintf(str, "%04d%02d%02d", y, m, d);
        if (check1(str))
        {
            if (!found1) puts(str), found1 = true;
            if (check2(str) && !found2) puts(str), found2 = true;
        }
    }

    return 0;
}